
//check input
function fn_add(){	
		var obj = document.cmtAddfrm;

		if(obj.cmt_writer.value != 'name' && obj.cmt_pass.value != 'pass'){
			if(obj.cmt_content.value != ""){
				obj.submit();
			}else{
				alert("내용을 입력해주세요.");
			}
		}else{
			alert("아이디나 비밀번호를 입력하지 않으셨습니다.");
			obj.cmt_writer.focus();
		}
}

//delete table view
function addDelElement(id,cmtNo,boardNo){
		var hideDiv = document.getElementById("commentList"+id);
		var delView = document.getElementById("delView"+id);
		hideDiv.style.display = "none";
		delView.style.display = "block";
		
		delView.innerHTML ="<form action='./cmtDel.action' method='post' name='cmtDelfrm' style='padding: 0px; margin: 0px;'>" +
						   "<table width='750' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='padding-left: 5px;'>" +
						   "<tr align='center' class='r_sm' style='padding:10px 0 0 0;'><td>비밀번호를 입력해주세요</td></tr>"+
						   "<tr><td align='center' height='30'><input type='password' name='cmt_pass' class='cmt_pass' maxlength='4'></td></td>" +
						   "<tr><td align='center'>" +
						   "<input type='button' class='cmt_btn' value='삭제' onclick='fn_del();'>" +
						   "<input type='button' class='cmt_btn' value='취소' onclick=fn_change("+ id +",'del');>" +
						   "</td></td>" +
						   "<tr><td height='1' colspan='2' bgcolor='#e9e9e9'></td></tr>" +
						   "</table>" +
						   "<input type='hidden' name='cmt_no' value='"+ cmtNo +"'>" +
						   "<input type='hidden' name='cmt_bnum' value='"+ boardNo +"'>" +
						   "<input type='hidden' name='cmd' value='delete'>" +
						   "</form>";
	}

//delete table display on/off
function fn_change(id,state){
	var view = null;
	if(state == 'del'){
		view = document.getElementById("delView"+id);
	}else if(state == 'modfiy'){
		view = document.getElementById("cmtUpdate"+id);
	}
	var hideDiv = document.getElementById("commentList"+id);
	view.innerHTML = "";
	view.style.display = "none";
	hideDiv.style.display = "block";
}

/*
 * 
 * comment ajax, callback function, innerhtml
 * 
 * 
 */
function modifyComment(cmtNo, id, boardNo) {
		 var req = newXMLHttpRequest();
		 req.onreadystatechange = getReadyStateHandler(req, updateComment); 
		 req.open("POST", "./cmtInfo.action", true);
		 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8;");
		 req.send("cmt_no = " + cmtNo +"&view_id = " + id +"&cmt_bnum="+boardNo);
}

//call back function
function updateComment(xml) {
	  var cmtlist = xml.getElementsByTagName("comment")[0];
	  
	  var cmtNo = cmtlist.getElementsByTagName("no")[0].firstChild.nodeValue;
	  var cmtContent = cmtlist.getElementsByTagName("content")[0].firstChild.nodeValue;
	  var cmtWriter = cmtlist.getElementsByTagName("writer")[0].firstChild.nodeValue;
	  var cmtDate = cmtlist.getElementsByTagName("regdate")[0].firstChild.nodeValue;
	  var id = cmtlist.getElementsByTagName("viewNo")[0].firstChild.nodeValue;
	  var boardNo = cmtlist.getElementsByTagName("boardNo")[0].firstChild.nodeValue;
	  addModifyElemet(id, cmtNo, boardNo, cmtWriter, cmtContent);
}

//innerHTML
function addModifyElemet(id, cmtNo, boardNo, user, content){
	var hideDiv = document.getElementById("commentList"+id);
	var upDateView = document.getElementById("cmtUpdate"+id);
	hideDiv.style.display = "none";
	upDateView.style.display = "block";
	upDateView.innerHTML ="<form action='./cmtModify.action' method='post' name='cmtUpdatefrm' style='padding: 0px; margin: 0px;'>"+
						  "<table width='750' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff' style='padding-left: 5px;'>"+
						  "<td width='610'><textarea class='textarea2' name='cmt_content'>"+ content +"</textarea></td>"+
						  "<td width='160' valign='bottom'>"+
						  "<input type='text' class='cmt_input' name='cmt_writer' disabled='disabled' value='"+ user +"' style='color: #979797;'><br>"+
						  "<input type='password' class='cmt_input' name='cmt_pass' id='cmt_p' onfocus='fn_pw();' style='color: #979797;' maxlength='4'><br>"+
						  "<input type='button' class='cmt_btn' value='수정' style='margin-left:-1px;' onclick=fn_mod();>"+
						  "<input type='button' class='cmt_btn' value='취소' onclick=fn_change("+ id +",'modfiy');>"+
						  "</td>"+
						  "</tr>"+
						  "<tr><td height='1' colspan='2' bgcolor='#e9e9e9'></td></tr>"+
						  "</table>"+
						  "<input type='hidden' name='cmt_no' value='"+ cmtNo +"'>"+
						  "<input type='hidden' name='cmt_bnum' value='"+ boardNo +"'>"+
						  "<input type='hidden' name='cmd' value='modify'>"+
						  "</form>";
}

